<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Feedback extends Site_Controller {

	public function __construct(){
		parent::__construct();
	}

	public function index()
	{
		if($this->input->post('send')){
			$this->form_validation->set_rules('fullName', 'Full name', 'trim|required|alpha');
			$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
			$this->form_validation->set_rules('phone', 'phone', 'trim|required|max_length[25]');
			$this->form_validation->set_rules('subject', 'subject', 'trim|required');
			$this->form_validation->set_rules('message', 'Message', 'trim|required');
			$this->form_validation->set_error_delimiters('<div class="red">', '</div>');
			
			if ($this->form_validation->run() == TRUE)
			{
				$this->load->library('email');
					
				$config['charset']    = 'utf-8';
				$config['mailtype'] = 'html'; // or html
				$config['validation'] = TRUE; // bool whether to validate email or not      
		
				$this->email->initialize($config);
				//set message for sending mail
				$name = $this->input->post('fullName');
				$email = $this->input->post('email');
				$phone = $this->input->post('phone');
				$subject = $this->input->post('subject');
				$message = $this->input->post('message');
				
				$message = '<!DOCTYPE html /></head>';
				//$message .= '<p style="font-weight: bold;">Dear &nbsp; All,</p>';
				$message .= '<p>My name is '.$name.'</p>';
				$message .= '<p>My phone number is '.$phone.'</p>';
				$message .= '<p>'.$msg.'</p>';

			   // recipient, sender, subject, and you message
				$to = CONTACT_SEND_TO_EMAIL;
				$from = $email;
				//$subject = $subject;
				
				// load the email library that provided by CI
				
				// this will bind your attributes to email library
				$this->email->set_newline("\r\n");
				$this->email->from($from, $fn." ".$ln);
				$this->email->to($to);
				$this->email->subject($subject);
				$this->email->message($message);
		 
				// send your email. if it produce an error it will print 'Fail to send your message!' for you
				if($this->email->send()) {
					
					$this->session->set_userdata('success-ms', 'Successfully, thank you!');
					redirect('content/feedback');
				} else {
					$this->session->set_userdata('error-ms', 'Sending error, please try again!');
					redirect('content/feedback');
				}
			}
		}
		
		$data['title']	= 'Feedback';
		$data['page']	= 'content/feedback/view';
		$data['action']	= 'Customers Feedback';
		$this->load->view('layout/layout',$data);
	}
}